package com.pan.admin.meta;

import com.gitee.apanlh.util.base.CollUtils;
import com.gitee.apanlh.util.base.Eq;
import com.gitee.apanlh.util.valid.ValidParam;
import com.pan.admin.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *  计划
 *
 *  @author Pan
 */
@Component
public class MetaPlanOnline {

    private static final String KEY = "api_plan_docking:all";

    @Autowired
    private RedisCache redisCache;

    /**
     *  获取缓存
     *
     *  @return List
     */
    public List<String> getCache() {
        return redisCache.getCacheList(KEY);
    }

    /**
     *  检测是否计划上线
     *
     *  @return boolean
     */
    public boolean hasOnline(Long productId, List<String> listOnline) {
        if (ValidParam.isNotEmpty(listOnline)) {
            //  设置上线状态
            if (CollUtils.indexOf(listOnline, onlineId -> Eq.str(productId.toString(), onlineId)) == -1) {
                return false;
            } else {
                return true;
            }
        }
        return false;
    }
}
